import request from '@/utils/request.js'

const wf_ProcessInstanceApi = {
  list: '/wf_ProcessInstance/list',
  save: '/wf_ProcessInstance/save',
  view: '/wf_ProcessInstance/view',
  del: '/wf_ProcessInstance/delete',
  dels: '/wf_ProcessInstance/batchDel',
  output: '/wf_ProcessInstance/output',
  getProcessExecut: 'flow/getProcessExecut',
  getProcessEnd: 'flow/getProcessEnd',
  loadProcessForm: 'flow/loadProcessForm',
  getProcessVariable: 'flow/getProcessVariable',
  getHandleParams: 'flow/getHandleParams',
  aplExecutor: 'flow/aplExecutor',
  findTaskIdByApplyno: 'flow/findTaskIdByApplyno',
  queryFainstid: 'flow/queryFainstid',
  queryTaskidByInstid: 'flow/queryTaskidByInstid',
}

/**
 * 查询流程当前所处任务的taskid
 * @param processinstanceid
 * @return
 */
 export function queryTaskidByInstid(processinstanceid) {
  return request({
    url: wf_ProcessInstanceApi.queryTaskidByInstid,
    method: 'post',
    params: {
      processinstanceid
    },
  })
}

/**
 * 查询子流程关联的父流程id
 * @param processinstanceid
 * @return
 */
 export function queryFainstid(processinstanceid) {
  return request({
    url: wf_ProcessInstanceApi.queryFainstid,
    method: 'post',
    params: {
      processinstanceid
    },
  })
}

/**
 * 查询流程任务的执行人, 没有进行抢占
 * @param taskid 
 * @param userid 
 * @returns 
 */
export function aplExecutor(taskid, userid) {
  return request({
    url: wf_ProcessInstanceApi.aplExecutor,
    method: 'get',
    params: {
      taskid,
      userid
    },
  })
}

/**
 * 查询处理页面所需参数
 * @param taskid
 * @return
 */
export function getHandleParams(taskid) {
  return request({
    url: wf_ProcessInstanceApi.getHandleParams,
    method: 'post',
    params: {
      taskid
    },
  })
}

/**
 * 查询流程实例的流程变量
 * @param processinstanceid (流程实例id, 对应act_ru_execution表PROC_INST_ID_字段)
 * @return
 */
export function getProcessVariable(processinstanceid) {
  return request({
    url: wf_ProcessInstanceApi.getProcessVariable,
    method: 'post',
    params: {
      processinstanceid
    },
  })
}


/**
 * 读取流程表单数据
 * @param formid
 * @param processinstanceid
 * @param state 1 进行中流程实例表单数据, 2. 已完结的流程实例表单数据
 * @return
 */
export function loadProcessForm(formid, processinstanceid, state) {
  return request({
    url: wf_ProcessInstanceApi.loadProcessForm,
    method: 'post',
    params: {
      formid,
      processinstanceid,
      state
    },
  })
}

/**
 * 根据流程实例id查询进行中的执行实例
 * @param processinstanceid (流程实例id, 对应act_ru_execution表PROC_INST_ID_字段)
 * @return
 */
export function getProcessEnd(processinstanceid) {
  return request({
    url: wf_ProcessInstanceApi.getProcessEnd,
    method: 'post',
    params: {
      processinstanceid
    },
  })
}

/**
 * 根据流程实例id查询进行中的执行实例
 * @param processinstanceid (流程实例id, 对应act_ru_execution表PROC_INST_ID_字段)
 * @return
 */
export function getProcessExecut(processinstanceid) {
  return request({
    url: wf_ProcessInstanceApi.getProcessExecut,
    method: 'post',
    params: {
      processinstanceid
    },
  })
}


/**
 * 导出流程实例
 */
export function output(data) {
  return request({
    url: wf_ProcessInstanceApi.output,
    method: 'post',
    data: data,
    responseType: 'blob'
  })
}
/**
 * 批量删除流程实例
 * @param {*} parameter
 */
export function delWf_ProcessInstances(ids) {
  return request({
    url: wf_ProcessInstanceApi.dels + '/' + ids,
    method: 'post'
  })
}
/**
 * 删除流程实例
 * @param {*} id
 */
export function delWf_ProcessInstance(id) {
  return request({
    url: wf_ProcessInstanceApi.del + '/' + id,
    method: 'post'
  })
}
/**
 * 查看、编辑流程实例
 * @param {*} id
 */
export function viewWf_ProcessInstance(id) {
  return request({
    url: wf_ProcessInstanceApi.view + '/' + id,
    method: 'post'
  })
}
/**
 * 保存流程实例
 * @param {*} parameter
 */
export function saveWf_ProcessInstance(parameter) {
  return request({
    url: wf_ProcessInstanceApi.save,
    method: 'post',
    data: parameter
  })
}
/**
 * 查询流程实例列表
 * @param {*} parameter
 */
export function queryWf_ProcessInstanceList(parameter) {
  return request({
    url: wf_ProcessInstanceApi.list,
    method: 'post',
    data: parameter
  })
}

/**
 * 根据申请编号查询流程任务id
 * @returns 
 */
export function findTaskIdByApplyno(params) {
  return request({
    url: wf_ProcessInstanceApi.findTaskIdByApplyno,
    method: 'post',
    params: params
  })
}